package com.haoxiaozhang.hxz_app.adapter;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.haoxiaozhang.hxz_app.R;
import com.haoxiaozhang.hxz_app.bean.Employee;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class EmployeesAdapter extends RecyclerView.Adapter<EmployeesAdapter.EmployeesViewHolder> {

    private Context mContext;
    private LayoutInflater mInflater;
    private List<Employee> mListData;

    public EmployeesAdapter(Context context, List<Employee> datas){
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mListData = datas;

        Log.d("TAG1", String.valueOf(mListData));
    }

    @NonNull
    @Override
    public EmployeesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = mInflater.inflate(R.layout.list_item_employees,parent,false);
        return new EmployeesViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull EmployeesViewHolder holder, int position) {
        Employee employee = mListData.get(position);

        holder.tv_name.setText(employee.getOu_name());
        holder.tv_phone.setText(employee.getOu_phone());

        if(employee.getEnterpriseStructure() == 0){
            holder.tv_distribution.setTextColor(Color.parseColor("#999999"));
            holder.tv_distribution.setText("未分配");
        }else{
            holder.tv_distribution.setTextColor(Color.parseColor("#4ab799"));
            holder.tv_distribution.setText("已分配");
        }

        if(employee.getOu_status().equals("1")){
            holder.tv_status.setTextColor(Color.parseColor("#da3b3d"));
            holder.tv_status.setText("离职");
        }else{
            holder.tv_status.setTextColor(Color.parseColor("#24c8fc"));
            holder.tv_status.setText("正常");
        }

    }

    @Override
    public int getItemCount() {
        return mListData.size();
    }

    class EmployeesViewHolder extends RecyclerView.ViewHolder {

        TextView tv_name;
        TextView tv_phone;
        TextView tv_distribution;
        TextView tv_status;

        public EmployeesViewHolder(View itemView) {

            super(itemView);

            tv_name = itemView.findViewById(R.id.tv_name);
            tv_phone = itemView.findViewById(R.id.tv_phone);
            tv_distribution = itemView.findViewById(R.id.tv_distribution);
            tv_status = itemView.findViewById(R.id.tv_status);


        }
    }
}
